home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / kcl.lha / c / bitop.c < prev    next >
C/C++ Source or Header  |  1987-06-04  |  5KB  |  388 lines

  1. /*
  2. (c) Copyright Taiichi Yuasa and Masami Hagiya, 1984.  All rights reserved.
  3. Copying of this file is authorized to users who have executed the true and
  4. proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  5. */
  6. /*
  7.     bitop.c
  8.  
  9.     Sets and/or tests bits in the mark table.  The first 8 words of the
  10.     Lisp data area have their mark bits in the byte location pointed to
  11.     by MARK_TABLE, and the next 8 words in the next byte location,
  12.     and so on.
  13.  
  14.     GET_MARK_BIT(X)
  15.     Returns 1 if the mark bit for the word address X is on.  Otherwise,
  16.     returns 0.
  17.  
  18.     SET_MARK_BIT(X)
  19.     Sets on the mark bit for the word address X.
  20.  
  21.     GET_SET_MARK_BIT(X)
  22.     Sets on the mark bit for the word address X, and returns 1 if the
  23.     mark bit was previously on.  Returns 0 otherwise.
  24.  
  25. */
  26. #include "include.h"
  27.  
  28. #ifdef VAX
  29.  
  30. get_mark_bit(x)
  31. int *x;
  32. {
  33.     asm("    ashl    $-2,4(ap),r2");
  34.     asm("    ashl    $-3,r2,r3");
  35.     asm("    bicl2    $-8,r2");
  36.     asm("    clrl    r0");
  37.     asm("    addl2    _mark_table,r3");
  38.     asm("    bbc    r2,(r3),1f");
  39.     asm("    incl    r0");
  40.     asm("1:");
  41. }
  42.  
  43. set_mark_bit(x)
  44. int *x;
  45. {
  46.     asm("    ashl    $-2,4(ap),r2");
  47.     asm("    ashl    $-3,r2,r3");
  48.     asm("    bicl2    $-8,r2");
  49.     asm("    addl2    _mark_table,r3");
  50.     asm("    bbcs    r2,(r3),1f");
  51.     asm("1:");
  52. }
  53.  
  54. get_set_mark_bit(x)
  55. int *x;
  56. {
  57.     asm("    ashl    $-2,4(ap),r2");
  58.     asm("    ashl    $-3,r2,r3");
  59.     asm("    bicl2    $-8,r2");
  60.     asm("    clrl    r0");
  61.     asm("    addl2    _mark_table,r3");
  62.     asm("    bbcs    r2,(r3),1f");
  63.     asm("    incl    r0");
  64.     asm("1:");
  65. }
  66.  
  67. #endif
  68.  
  69. #ifdef MC68K
  70.  
  71. get_mark_bit(x)
  72. int *x;
  73. {
  74.     asm("    movl    a6@(8),d0");
  75.     asm("    lsrl    #2,d0");
  76.     asm("    movl    d0,d1");
  77.     asm("    lsrl    #3,d1");
  78.     asm("    movl    _mark_table,a0");
  79.     asm("    btst    d0,a0@(0,d1:L)");
  80.     asm("    sne    d0");
  81.     asm("    andl    #1,d0");
  82. }
  83.  
  84. set_mark_bit(x)
  85. int *x;
  86. {
  87.     asm("    movl    a6@(8),d0");
  88.     asm("    lsrl    #2,d0");
  89.     asm("    movl    d0,d1");
  90.     asm("    lsrl    #3,d1");
  91.     asm("    movl    _mark_table,a0");
  92.     asm("    bset    d0,a0@(0,d1:L)");
  93. }
  94.  
  95. get_set_mark_bit(x)
  96. int *x;
  97. {
  98.     asm("    movl    a6@(8),d0");
  99.     asm("    lsrl    #2,d0");
  100.     asm("    movl    d0,d1");
  101.     asm("    lsrl    #3,d1");
  102.     asm("    movl    _mark_table,a0");
  103.     asm("    bset    d0,a0@(0,d1:L)");
  104.     asm("    sne    d0");
  105.     asm("    andl    #1,d0");
  106. }
  107.  
  108. #endif
  109.  
  110. #ifndef NEWS
  111. #ifdef MC68020
  112.  
  113. get_mark_bit(x)
  114. int *x;
  115. {
  116.     asm("    movl    a6@(8),d0");
  117.     asm("    lsrl    #2,d0");
  118.     asm("    movl    d0,d1");
  119.     asm("    lsrl    #3,d1");
  120.     asm("    movl    _mark_table,a0");
  121.     asm("    btst    d0,a0@(0,d1:L)");
  122.     asm("    sne    d0");
  123.     asm("    andl    #1,d0");
  124. }
  125.  
  126. set_mark_bit(x)
  127. int *x;
  128. {
  129.     asm("    movl    a6@(8),d0");
  130.     asm("    lsrl    #2,d0");
  131.     asm("    movl    d0,d1");
  132.     asm("    lsrl    #3,d1");
  133.     asm("    movl    _mark_table,a0");
  134.     asm("    bset    d0,a0@(0,d1:L)");
  135. }
  136.  
  137. get_set_mark_bit(x)
  138. int *x;
  139. {
  140.     asm("    movl    a6@(8),d0");
  141.     asm("    lsrl    #2,d0");
  142.     asm("    movl    d0,d1");
  143.     asm("    lsrl    #3,d1");
  144.     asm("    movl    _mark_table,a0");
  145.     asm("    bset    d0,a0@(0,d1:L)");
  146.     asm("    sne    d0");
  147.     asm("    andl    #1,d0");
  148. }
  149.  
  150. #endif
  151. #endif
  152.  
  153. #ifdef ATT3B2
  154.  
  155. get_mark_bit(x)
  156. int *x;
  157. {
  158.     asm("    subw3    &0x80800000,0(%ap),%r1"); /* R1 <= address offset */
  159.     asm("    lrsw3    &2,%r1,%r1");        /* R1 <= bit offset */
  160.     asm("    lrsw3    &3,%r1,%r0");        /* R0 <= byte offset */
  161.     asm("    andw2    &0x7,%r1");
  162.     asm("    addw2    mark_table, %r0");
  163.     asm("    movb    0(%r0),%r0");        /* R0 <= table entry */
  164.     asm("    lrsw3    %r1,%r0,%r0");
  165.     asm("    andw2    &1,%r0");        /* LSB(R0) = the bit */
  166. }
  167.  
  168. set_mark_bit(x)
  169. int *x;
  170. {
  171.     asm("    subw3    &0x80800000,0(%ap),%r0"); /* R0 <= address offset */
  172.     asm("    lrsw3    &2,%r0,%r0");        /* R0 <= bit offset */
  173.     asm("    lrsw3    &3,%r0,%r1");        /* R1 <= byte offset */
  174.     asm("    andw2    &0x7,%r0");
  175.     asm("    llsw3    %r0,&1,%r0");        /* R0 <= mask */
  176.     asm("    addw2    mark_table,%r1");
  177.     asm("    orb2    %r0,0(%r1)");
  178. }
  179.  
  180. get_set_mark_bit(x)
  181. int *x;
  182. {
  183.     register int *r8;
  184.  
  185.     asm("    subw3    &0x80800000,0(%ap),%r1"); /* R1 <= address offset */
  186.     asm("    lrsw3    &2,%r1,%r1");        /* R1 <= bit offset */
  187.     asm("    lrsw3    &3,%r1,%r2");        /* R2 <= byte offset */
  188.     asm("    andw2    &0x7,%r1");
  189.     asm("    addw2    mark_table,%r2");
  190.     asm("    movb    0(%r2),%r0");        /* R0 <= table entry */
  191.     asm("    llsw3    %r1,&1,%r8");        /* R8 <= mask */ 
  192.     asm("    orb2    %r8,0(%r2)");        /* set */
  193.     asm("    lrsw3    %r1,%r0,%r0");
  194.     asm("    andw2    &1,%r0");        /* get */
  195. }
  196.  
  197. #endif
  198.  
  199. #ifdef NS32K
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236. #endif
  237.  
  238. #ifdef S3000
  239.  
  240. extern int *mark_table;
  241.  
  242. get_mark_bit(x)
  243. int x;
  244. {
  245.     int y;
  246.  
  247.     y = (*(mark_table+(x/4/32)) >> (x/4%32)) & 1;
  248.     return(y);
  249. }
  250.  
  251. set_mark_bit(x)
  252. int x;
  253. {
  254.     int y;
  255.  
  256.     y = 1 << (x/4%32);
  257.     y = (*(mark_table+(x/4/32))) | y;
  258.     *(mark_table+ (x/4/32))=y;
  259. }
  260.  
  261. get_set_mark_bit(x)
  262. int x;
  263. {
  264.     int y;
  265.  
  266.     y = get_mark_bit(x);
  267.     set_mark_bit(x);
  268.     return(y);
  269. }
  270.  
  271. #endif
  272.  
  273. #ifdef IBMRT
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346. #endif
  347.  
  348. #ifdef NEWS
  349.  
  350. get_mark_bit(x)
  351. int *x;
  352. {
  353.     asm("    move.l    (8,fp),d0");
  354.     asm("    lsr.l    #2,d0");
  355.     asm("    move.l    d0,d1");
  356.     asm("    lsr.l    #3,d1");
  357.     asm("    move.l    _mark_table,a0");
  358.     asm("    btst    d0,0(a0,d1.l)");
  359.     asm("    sne    d0");
  360.     asm("    and.l    #1,d0");
  361. }
  362.  
  363. set_mark_bit(x)
  364. int *x;
  365. {
  366.     asm("    move.l    (8,fp),d0");
  367.     asm("    lsr.l    #2,d0");
  368.     asm("    move.l    d0,d1");
  369.     asm("    lsr.l    #3,d1");
  370.     asm("    move.l    _mark_table,a0");
  371.     asm("    bset    d0,0(a0,d1.l)");
  372. }
  373.  
  374. get_set_mark_bit(x)
  375. int *x;
  376. {
  377.     asm("    move.l    (8,fp),d0");
  378.     asm("    lsr.l    #2,d0");
  379.     asm("    move.l    d0,d1");
  380.     asm("    lsr.l    #3,d1");
  381.     asm("    move.l    _mark_table,a0");
  382.     asm("    bset    d0,0(a0,d1.l)");
  383.     asm("    sne    d0");
  384.     asm("    and.l    #1,d0");
  385. }
  386.  
  387. #endif
  388.